package ${package.ServiceImpl};

import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eairlv.cli.utils.request.PageBO;
import com.eairlv.cli.utils.request.PageUtil;
import com.eairlv.cli.utils.request.PageVO;
import com.eairlv.cli.utils.bean.BeanUtil;
import ${package.Entity}.${entity};
import ${package.Entity}.${cfg.vo};
import ${package.Entity}.${cfg.bo};
import ${package.Entity}.${cfg.updateBO};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Slf4j
@Service
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {

    @Autowired
    ${table.mapperName} ${cfg.objectMapperName};

    /**
     * <p>
    * 通过ID获取对象
    * </p>
     *
     */
    public ${cfg.vo} get(Integer id) {
        return BeanUtil.copyProperties(${cfg.objectMapperName}.selectById(id), ${cfg.vo}.class);
    }

    /**
     * <p>
    * 新增对象
    * </p>
     *
     */
    public Object add(${cfg.bo} ${cfg.boVariable}) {
        ${cfg.po} ${cfg.poVariable} = new ${cfg.po}();
        BeanUtil.copyProperties(${cfg.boVariable}, ${cfg.poVariable});
        ${cfg.objectMapperName}.insert(${cfg.poVariable});
        return ${cfg.poVariable}.getId();
    }

    /**
     * <p>
    * 修改对象
    * </p>
     *
     */
    public void update(${cfg.updateBO} ${cfg.updateBOVariable}) {
        ${cfg.objectMapperName}.updateById(BeanUtil.copyProperties(${cfg.updateBOVariable}, ${cfg.po}.class));
    }

    /**
     * <p>
    * 删除对象
    * </p>
     *
     */
    public void delete(Long id) {
        ${cfg.objectMapperName}.deleteById(id);
    }

    /**
     * <p>
    * 获取分页对象
    * </p>
     *
     */
    public PageVO<${cfg.vo}> pageView(PageBO pageBO) {
        QueryWrapper<${cfg.po}> queryWrapper = new QueryWrapper<>();
        PageVO pageVO = PageUtil.voTransform(${cfg.objectMapperName}.selectPage(PageUtil.boTransform(pageBO), queryWrapper));
        pageVO.setData(BeanUtil.copyProperties(pageVO.getData(), ${cfg.vo}.class));
        return pageVO;
    }
}
